﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using SimpleTaskManager.Domain.Abstract;
using SimpleTaskManager.Domain.Entities;

namespace SimpleTaskManager.Domain.Concrete
{
    /// <summary>
    /// A repository containing the connector collection between the Users and Skills
    /// </summary>
    public class EFUser_SkillRepository : IUser_SkillRepository
    {
        private EFDbContext context = new EFDbContext();

        /// <summary>
        /// Gets the collection representing a many-to-many relationship between Users and Skills
        /// </summary>
        public IQueryable<User_Skill> User_Skills
        {
            get { return context.User_Skills; }
        }

        /// <summary>
        /// Deletes the User_skill (skill associated with some user)
        /// </summary>
        /// <param name="id">id of User_Skill that should be deleted</param>
        public void Delete(int id)
        {
            var uSkill = context.User_Skills.Single(us => us.User_SkillID == id);
            context.User_Skills.Remove(uSkill);
            context.SaveChanges();
        }

        /// <summary>
        /// Edits the User_Skill (Skill associated with some user)
        /// </summary>
        /// <param name="skill">edited User_skill that should be saved to database</param>
        public void EditSkill(User_Skill skill)
        {
            context.Entry(skill).State = EntityState.Modified;
            context.SaveChanges(); 
        }
    }
}
